batch: comparing filenames and renaming [migrated]

Posted by user2978770 on Programmers See other posts from Programmers or by user2978770
Published on 2013-11-11T10:47:24Z Indexed on 2013/11/11 16:15 UTC
Read the original article Hit count: 274

Filed under:

i'm new to both this platform and batch programming and i'm slowly but steadily driving crazy :-(

I'm studying in Germany and just started on a bigger project that mainly consists of analyzing data and finding algorithms in order to maintain a certain function of a system.

In order to get started i got a bunch of recorded data that, unfortunately, is not consistent when i comes to naming. Normally all files (all in one folder) should start with SPY.SPYNODE.SIDE and then go on with the specific names for each values or variables. However, the data logger messed it up a couple of times and gives weird names like SP0E1A~1.csv (all files are .csv-files). An that's when i figured in stead of renaming a couple of thousand files manually i could "easily" use a simple batch file to do that job for name. And that's exactly when I started to go crazy :-)

So far i came up with the following:

FOR /R %%i in (%CD%) DO (
  set file1=%%i
  if not %file1%=="SPY.SPYNODE.SIDE" DO (
  set /p "filename" < %file1%
  rename %file1% %filename%
  )
)

So what i want it to do is this (in pseudo)

look through the whole folder and every file
    save the filename in variable file1
    if file1 partially equals SPY.SPYNODE.SIDE
        open the file and save the first line (which contains the correct name of the file) in variable filename
        rename the file with the correct filename

But so far it doesn't really work and i don't know why.

Could anybody give me a hint or some advice how i should proceed? I really appreciate any kind of help!

© Programmers or respective owner

Related posts about programming-languages